<template>

  <div class="con">
    <ol class="list">
      <li v-for="(item,index) in goods" :key="item.name" @click="flag(index)" :class= "index1===index?'active':''">
        <a :href="'#'+item.name" >{{ item.name }}</a>
        
 </li>
    </ol>
    <ul class="right">
      <li v-for="item in goods">
        <h3 :id="item.name">{{ item.name }}</h3>
        <ul>
          <li v-for="(item1, index) in item.foods" class="gt">
            <img :src="item1.image" alt="">
            <div>
              <p>
                {{ item1.name }}
              </p>
              <p>{{ item1.description }}</p>
              <p>
                月售1132份 好评率 100%
              </p>
              <div class="price">
                <h5>${{ item1.price }}<del v-show="item1.oldPrice > 0">${{ item1.oldPrice }}</del></h5>
                <btns :item="item1" :index="index" type="0"></btns>

              </div>
            </div>

          </li>
        </ul>
      </li>

    </ul>
  </div>
  <div class="zhegai" v-show="$store.state.show">
    <p class="zg">
      <p></p>
    </p>
    <div>
      <h4>购物车 <span @click="clear()">清空</span></h4>
      <ul>
        <li v-for="item in carList" v-show="item.count>0">
          <div class="left1">
            <p>{{ item.name }} </p>
            <span> ${{ item.price }}</span>
          </div>
          <div class="right1">

            <span @click="WWW(item)">-</span>
            <b>{{ item.count }}</b>
            <span @click="item.count++">+</span>

          </div>
        </li>
      </ul>
    </div>


  </div>
  <div class="shopCar" @click="showCar">
    <ul>
      <li class="one">
        <div >
          <span class="iconfont icon-gouwucheman"  v-show="!$store.state.show"></span>
          <span class="iconfont icon-gouwucheman"  v-show="$store.state.show" style="color: white;background-color: rgb(0, 160, 220);"></span>
          <p>{{ carList.length }}</p>
        </div>

        <span>${{ getPrice }}</span>
      </li>
      <li class="two">
        另外是需要配送费$4元
      </li>
      <li>
        <p v-show="getPrice >= 20" style="color: #f3f5f7; background-color: yellowgreen; height: 52px;">
          可以配送
        </p>
        <p v-show="getPrice < 20">
          还差{{ 20 - getPrice }}起送
        </p>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import "../font/iconfont.css"
import Btns from "./btns.vue"
export default {


  data() {
    return {
      index1:0
    };
  },
  components: {
    Btns,
  },
  created() {
    this.getGoods();
  },
  computed: {
    ...mapState(["goods", "price", "carList"]),
    getPrice() {
      let num = 0;
      this.carList.forEach((item) => {
        num += item.price * item.count;
      });
      return num;
    },

  },
  methods: {
    ...mapActions(["getGoods"]),
    add(food) {

      if (!food.count) {
        food.count = 1;
      } else {
        food.count++;
      }
      this.$store.commit("setCarList", {
        item: food,
      });
    },
    increment(food) {
      food.count--;
    },
    showCar() {
      console.log(1)
      this.$store.commit("showCar");
    },
    clear() {
      console.log(1)
      this.$store.commit("clearr");
    },
    flag(index){

      this.index1=index;
    
    },
    WWW(item){
      
      item.count--
      this.$store.commit("setCarList2", {
        count:item.count
      });
    
    }
      
  },
};
</script>

<style  scoped>
.active{
  background-color: white;

}
.active a{
   color: #333;
  font-weight: 800; 
}
* {
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  color: #333;
}

li {
  list-style: none;
  border-bottom: 1px solid rgba(7, 17, 27, 0.1);
}

.con {
  display: flex;
}

.con .list {
  height: 434px;
  width: 80px;
  background-color: #f3f5f7;
  overflow: auto;
}

.con .list li {
  box-sizing: border-box;
  height: 54px;
  /* width: 100%; */
  font-size: 12px;
  color: #333;
  font-weight: 200;
  line-height: 14px;
  padding: 12px;
  border-bottom: 2px solid rgba(7, 17, 27, 0.1);
}

.con .right {
  height: 434px;
  overflow: auto;
  flex: 1;
}

.con .right img {
  width: 80px;
  height: 80px;
}

.con .right h3 {

  height: 26px;
  line-height: 26px;
  font-size: 14px;
  color: rgba(7, 17, 27, 0.3);
  background-color: rgba(7, 17, 27, 0.1);
  border-left: solid 2px rgba(7, 17, 27, 0.2);
}

.con .right .gt {
  padding: 18px;
  display: flex;
}

.con .right .gt>div {
  margin-left: 10px;
  line-height: 1;
  flex: 1;
}

.con .right .gt>div p:nth-child(1) {
  font-size: 18px;
  font-weight: 800;

}

.con .right .gt>div p~p {
  font-size: 10px;
  color: rgb(147, 153, 159);
  margin-top: 8px;
}

.con .right .gt div .price {
  display: flex;
  justify-content: space-between;
  font-size: 20px;
  margin-top: 6px;
  color: rgb(240, 20, 20);
}

.con .right .gt div .price del {
  color: rgb(147, 153, 159);
  font-size: 10px;
  margin-left: 8px;
}

.shopCar {
  position: absolute;
  /* bottom: 48px; */
  background-color: #141d27;
  height: 52px;
  width: 350px;
  z-index: 11;
}

.shopCar ul {
  display: flex;
  justify-content: space-around;
}

.shopCar ul .one {
  display: flex;
  justify-content: space-between;
}

.shopCar ul .one div {
  width: 44px;
  height: 44px;
  border-radius: 44px;
  margin-top: -15px;
  background-color: #141d27;
  margin-left: 18px;
  font-size: 24px;
  position: relative;
}

.shopCar ul .one div span {
  margin-top: 5px;
  width: 34px;
  height: 34px;
  display: block;
  background-color: rgba(0, 0, 0, 0.2);
  /* background-color: aqua; */
  text-align: center;
  border-radius: 222px;
  color: rgba(255, 255, 255, 0.4);
  /* color: #f3f5f7; */
  line-height: 34px;
  margin-left: 5px;
}

.shopCar ul .one div p {
  color: white;
  width: 20px;
  height: 12px;
  border-radius: 10px;
  position: absolute;
  top: 0;
  font-size: 10px;
  background-color: red;
  right: 0;
  text-align: center;
  margin-right: -7px;
  line-height: 1;
}

.shopCar ul .one div~span {
  box-sizing: border-box;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.4);
  padding: 10px;
  border-right: 2px solid rgba(255, 255, 255, 0.4);
}

.shopCar ul .two {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 700;
  line-height: 50px;
}

.shopCar ul .two~li {
  width: 106px;
  background-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.4);
  line-height: 42px;
  text-align: center;
  height: 51px;
}


.zhegai .zg{
  position: absolute;
  width: 350px;
  height: 567px;
  top: 0;
  background-color: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  z-index: 1;


}


.zhegai>div {
  background-color: white;
  height: 300px;
  position: absolute;
  bottom: 50px;
  z-index: 10;
  width: 350px;

}

.zhegai>div h4 {
  position: absolute;
  height: 40px;
  background-color: #f3f5f7;
  top: 0;
  width: 340px;
}

.zhegai>div h4 span {
  content: "清空";
  float: right;
  color: rgb(0, 160, 220);
}

.zhegai>div ul {
  margin-top: 40px;
  height: 200px;
  overflow: auto;
}

.zhegai>div ul li {
  height: 48px;
  border-top: 2px solid rgba(7, 17, 27, 0.1);
  display: flex;
  justify-content: space-between;
}

.zhegai>div ul li .left1 {
  display: flex;
  justify-content: space-between;
  width: 240px;
}

.zhegai>div ul li .left1 p {
  font-size: 14px;
  color: rgb(7, 17, 27);
  line-height: 48px;
}

.zhegai>div ul li .left1 span {
  font-size: 14px;
  font-weight: 700;
  color: rgb(240, 20, 20);
  line-height: 48px;
}

.zhegai>div ul li .right1 {
  display: flex;
  justify-content: space-around;
  width: 80px;
  margin-top: 10px;
}
.zhegai>div ul li .right1 span {
display: block;
font-size: 30px;
line-height: 24px;
width: 30px;
height: 30px;
border-radius: 30px;
background-color: rgb(0, 160, 220);
text-align: center;
color: azure;
}

</style>
